<?php
/**
 * Enter description here...
 *
 */
require_once   BaseUtil::getModulePath("base")  .  '/validate/Unique.php';

class BaseService
{
    /**
     * @var Zend_Db_Adapter_Abstract
     */
    protected $db;
    
    protected $db_r;
    
    protected $db_w;

    protected $_translate = null;

    public function __construct ($components = array())
    {
        $this->db_w = Zend_Db_Table::getDefaultAdapter();
        $this->db_r = Zend_Registry::get("db_r");
        $this->db['db_r'] = $this->db_r;
        $this->db['db_w'] = $this->db_w;
        $this->_translate = Zend_Registry::get('Zend_Translate');
    }

    public function unique($table,$field,$value,$id=null){
        $validate = new MyValid_Unique();
        $validate->setTableName($table);
        $validate->setFieldName($field);
        if(!empty($id)){
            $validate->setId(trim($id));
        }
        return $validate->isValid(trim($value));
    }
    
    protected function getLoginUserName(){
    	$loginUser = BaseUtil::getLoginUser();
    	if(!empty($loginUser)){
            return $loginUser['uname'];
    	}
    	return "";
    }

//    protected function beginTransaction ()
//    {
//        $this->db->beginTransaction();
//    }
//    protected function commit ()
//    {
//        $this->db->commit();
//    }
//    protected function rollBack ()
//    {
//        $this->db->rollBack();
//    }
}

